package com.ooqiu.gaming.injector.modules;


import com.ooqiu.gaming.GamingApp;
import com.ooqiu.gaming.api.FileManager;
import com.ooqiu.gaming.api.GamingApi;
import com.ooqiu.gaming.api.repository.InformationRepository;
import com.ooqiu.gaming.components.net_interceptor.ReqInterceptor;
import com.ooqiu.gaming.components.storage.UserStorage;
import com.umeng.socialize.UMShareAPI;

import java.util.concurrent.TimeUnit;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import okhttp3.OkHttpClient;

/**
 * Created by Eenie on 2017/5/3.
 * Email: eeniework@gmail.com
 * Des:
 */

@Module
public class AppModule {

    private GamingApp mApp;

    public AppModule(GamingApp app) {
        this.mApp = app;
    }


    @Singleton
    @Provides
    public GamingApp provideApp() {
        return mApp;
    }


    @Singleton
    @Provides
    public OkHttpClient providerClient() {
        return new OkHttpClient.Builder()
                .addInterceptor(new ReqInterceptor())
                .connectTimeout(30, TimeUnit.SECONDS)
                .readTimeout(30, TimeUnit.SECONDS)
                .writeTimeout(30, TimeUnit.SECONDS)
                .build();
    }

    @Singleton
    @Provides
    public GamingApi providerGamingApi(OkHttpClient client, UserStorage userStorage) {
        return new GamingApi(client, userStorage);
    }

    @Singleton
    @Provides
    public InformationRepository providerRepository(GamingApp gamingApp, GamingApi gamingApi) {
        return new InformationRepository(gamingApp, gamingApi);
    }


    @Singleton
    @Provides
    public UserStorage providerUserStorage(GamingApp gamingApp) {
        return new UserStorage(gamingApp);
    }
    @Singleton
    @Provides
    public FileManager providerFileManager(OkHttpClient client) {
        return new FileManager(client);
    }
    @Singleton
    @Provides
    public UMShareAPI providerUMShareAPI(GamingApp gamingApp) {
        return  UMShareAPI.get(gamingApp);
    }


}
